package org.example.controller;

import org.example.domain.po.R;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.example.domain.po.ErpDepotHead;
import org.example.domain.po.ErpDepotItem;
import org.example.service.ErpDepotHeadService;
import org.example.service.ErpDepotItemService;


import java.util.Date;

@RestController
@RequestMapping("/salee")
public class SaleController {

    private final ErpDepotHeadService erpDepotHeadService;
    private final ErpDepotItemService erpDepotItemService;

    public SaleController(ErpDepotHeadService erpDepotHeadService, ErpDepotItemService erpDepotItemService) {
        this.erpDepotHeadService = erpDepotHeadService;
        this.erpDepotItemService = erpDepotItemService;
    }

    @PostMapping("/add")
    public R add(@RequestBody ErpDepotHead erpDepotHead, @RequestBody ErpDepotItem erpDepotItem) {
        erpDepotHead.setDefaultNumber(erpDepotHead.getNumber());
        erpDepotItem.setHeaderId(erpDepotHead.getId());
        erpDepotHead.setCreateTime(new Date());
        erpDepotHead.setOperTime(new Date());
        erpDepotItemService.save(erpDepotItem);
        erpDepotHeadService.save(erpDepotHead);
        return R.success();
    }
}
